<?php
namespace app\admin\service;

class AdminService
{
    public function index($filter)
    {
        
        $admin = model('admin');
        $where = [
            "type"=>2,
            "a.delete_time"=>0
        ];
        $join = [
            ['__AUTH_GROUP_ACCESS__ auth_group_access','a.id = auth_group_access.uid'],
            ['__AUTH_GROUP__ auth_group','auth_group.id = auth_group_access.group_id'],
        ];
         
        $field = 'a.*,auth_group.title,auth_group.rules';
 
        //条件查询
        $startTime = empty($filter['start_time']) ? 0 : strtotime($filter['start_time']);
        $endTime   = empty($filter['end_time']) ? 0 : strtotime($filter['end_time']);
        if (!empty($startTime) && !empty($endTime)) {
            $where['a.create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['a.create_time'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['a.create_time'] = ['<= time', $endTime];
            }
        }
        
        $keyword = empty($filter['keyword']) ? '' : $filter['keyword'];
        if (!empty($keyword)) {
            $where['a.name'] = ['like', "%$keyword%"];
        }
        /*
        $sightid = empty($filter['sightid']) ? 0 : intval($filter['sightid']);
        if (!empty($sightid)) {
            $where['b.id'] = ['in', $sightid];
            array_push($join, [
                '__SIGHTID__ b', 'a.id = b.id'
            ]);
            $field = 'a.*,b.id AS sightid_id,b.name as sightid_name,u.user_login,u.user_nickname,u.user_email';
        }
         

        $jingdianModel = new JingdianModel();*/
        $admin = $admin->where($where)->join($join)->alias('a')->field($field)->paginate(10);
        return $admin;
    
    }
}

